<?php

namespace Upfor\UpforPHP\Cache;

abstract class AbstractCache {

    /**
     * Prefix
     *
     * @var string
     */
    protected $prefix = '';

    /**
     * Cache config options
     *
     * @var array
     */
    protected $options = [];

    /**
     * Cache object
     *
     * @var object
     */
    protected static $cacheObj;

    /**
     * Get current options
     *
     * @return array
     */
    public function getOptions() {
        return $this->options;
    }

    /**
     * Sets the cache key prefix
     *
     * @access public
     * @param  string $prefix
     */
    public function setPrefix($prefix) {
        $this->prefix = (string) $prefix;
    }

    /**
     * Returns the cache key prefix
     *
     * @return string
     */
    public function getPrefix() {
        return $this->prefix;
    }

    /**
     * Returns a prefixed key
     *
     * @param  string $key
     * @return string
     */
    protected function createKey($key) {
        return md5(empty($this->prefix) ? $key : $this->prefix . '.' . $key);
    }

}
